package br.com.decorando.activity;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import br.com.decorando.dao.PerfilDao;
import br.comdecorando.adapter.MainAdapter;


public class MainActivity extends Activity {
	private PerfilDao perfilDao = new PerfilDao(this);
	TextView textTeste = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);    
        atualizaLista();
    }
    
    @Override
    protected void onStart() {
    	super.onPause();
    	atualizaLista();    	
    }
    
    @Override
    protected void onResume() {
    	super.onResume();
    	atualizaLista();    	
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {        
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
        
    }
    public void abrirAssuntos(View view){
    	Integer id = (Integer) view.getTag();
     	Intent intent = new Intent(this, AdicionaAssuntoActivity.class);
     	intent.putExtra("idPerfil", id);
    	startActivity(intent);
    }
    
    @Override
	public boolean onOptionsItemSelected(MenuItem item) {
    	Intent intent;
    	switch (item.getItemId()) {
			case R.id.menu_perfil:
				intent = new Intent(this, PerfilActivity.class);
				startActivity(intent);
				return true;
			default:
				return super.onOptionsItemSelected(item);
		}
    }
    
    public void atualizaLista() {
    	ListView listView = (ListView) findViewById(R.id.listMain);        
        MainAdapter adapter = new MainAdapter(this, R.layout.list_main, perfilDao.listAtivos());
        listView.setAdapter(adapter);
	}
}
